//
//  PlayerHouse.m
//  gong
//
//  Created by echo on 14-1-11.
//  Copyright (c) 2014年 echo. All rights reserved.
//

#import "PlayerHouse.h"
#import "SimpleAudioEngine.h"
#import "MusicBeatManager.h"
#import "ASTouchVisualizer.h"

@implementation PlayerHouse
{
    MusicBeatManager *_beatManager;
    UIButton *_beginDanceButton;
}

- (void)dealloc
{
    [_beginDanceButton removeFromSuperview];
    [_beatManager clear];
}

- (void)initDefault
{
    [super initDefault];
    
    self.name = @"家";
    _bk = @"home.jpg";
    _smallImage = @"home-small.png";
    _rankLimit = 0;
    
    _placeClassName = @"PlayerHouse";
}

- (void)createDefault
{
    [super createDefault];
    [self initPlayerHouseView];    
}

- (void)initPlayerHouseView
{
    _beginDanceButton = [UICreator createButtonWithNormalImage:@"Minion-Dancing-icon"
                                                       highlightedImage:nil
                                                                 target:self
                                                                 action:@selector(beginDance)
                                                                  use2X:NO];
    [PositionTools placeView:_beginDanceButton atTheRightTopOfTheView:_containerView offset:CGSizeMake(20, 160)];
    _beatManager = [[MusicBeatManager alloc] initWithContainer:_containerView];
}

- (void)beginDance
{
//    [ASTouchVisualizer sharedTouchVisualizer].showEffect = YES;
    [[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
    [_beatManager playMusic];
}

- (void)leave
{
    [super leave];
    [_beginDanceButton removeFromSuperview];
//    [ASTouchVisualizer sharedTouchVisualizer].showEffect = NO;
    [_beatManager clear];
    _beatManager = nil;
}

- (void)handlePlaceTap:(UIGestureRecognizer*)gesture
{
    [_beatManager checkTouch];
}


@end
